package com.ruyuan.eshop.common.dao.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruyuan.eshop.common.dao.OrderQueryDAO;
import com.ruyuan.eshop.common.domain.dto.OrderQueryParam;
import com.ruyuan.eshop.common.domain.entity.OrderDO;
import com.ruyuan.eshop.common.domain.vo.OrderDetailVO;
import com.ruyuan.eshop.common.mapper.OrderQueryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 订单查询业务DAO
 * @author pwd
 * @version 1.0
 */
@Repository
public class OrderQueryDAOImpl implements OrderQueryDAO {

    @Autowired
    private OrderQueryMapper orderQueryMapper;

    /**
     * 按条件分页查询订单列表
     * @param page 分页参数
     * @param paramDTO 查询参数
     * @return
     */
    @Override
    public IPage<OrderDO> selectOrderQueryPage(Page page, OrderQueryParam paramDTO) {
        return orderQueryMapper.selectOrderQueryPage(page, paramDTO);
    }

    /**
     * 按条件查询订单导出列表
     * @param paramDTO 查询参数
     * @return
     */
    @Override
    public List<OrderDO> selectExportList(OrderQueryParam paramDTO) {
        return orderQueryMapper.selectExportList(paramDTO);
    }

    /**
     * 根据订单编号读取订单列表
     * @param tradeSn 订单编号
     * @return
     */
    @Override
    public List<OrderDetailVO> getOrderByTradeSn(String tradeSn) {
        return orderQueryMapper.getOrderByTradeSn(tradeSn);
    }

    /**
     * 获取几个月之内购买过相关商品的订单数据
     * @param beforeMonthDateline  几个月之前的时间戳
     * @param goodsId  商品id
     * @param memberId 会员id
     * @return
     */
    @Override
    public List<OrderDO> listOrderByGoods(long beforeMonthDateline,
                                   Long goodsId,
                                   Long memberId) {
        return orderQueryMapper.listOrderByGoods(beforeMonthDateline, goodsId, memberId);
    }

    /**
     * 根据订单编号查询货物相关信息
     * @param orderSn 订单编号
     * @return
     */
    @Override
    public List<Map> getItemsPromotionTypeandNum(String orderSn) {
        return orderQueryMapper.getItemsPromotionTypeandNum(orderSn);
    }
}
